<?php

namespace app\admin\controller\fiance;

use app\common\controller\Backend;
use think\Db;
use think\Controller;
use think\Request;

/**
 *
 *
 * @icon fa fa-circle-o
 */
class Forward  extends Backend
{

    /**
     * UserWarehouse模型对象
     */
    protected $model = null;
    protected $warehouse_items;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Recharge');
        //$this->warehouse_items = config('user_warehouse');

    }
    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('pkey_name'))
            {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $where = array();
            $filter=input();
            $filters = json_decode($filter['filter'], true);
            if(!empty($filters['user_id'])){
                $where['u.user_id']=$filters['user_id'];
            }
            if(!empty($filters['user_name'])){
                $where['u.user_name']=$filters['user_name'];
            }
            if(!empty($filters['full_name'])){
                $where['u.full_name']=array('like','%'.$filters['full_name'].'%');
            }
            if(!empty($filters['add_time'])) {
                $date = explode(',', $filters['add_time']);
                foreach($date as &$v){
                    $v = strtotime($v);
                }
                $where['add_time'] = array('between', $date);
            }
            $total = $this->model
                ->alias('a')
                ->join('users u','u.user_id=a.user_id')
                ->where($where)
                ->where('a.process_type','=',1)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->alias('a')
                ->join('users u','u.user_id=a.user_id')
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->where('a.process_type','=',1)
                ->select();
            foreach ($list as $key=>&$li){
                $list[$key]['add_time']=date('Y-m-d',$li['add_time']);
            }
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        $btns = ['refresh'];
        $this->view->assign('btns', $btns);
        return $this->view->fetch();
    }

}